#include <iostream>
#include <math.h>
using namespace std;

struct people{
	int index,len;
};

int find(int x,people *f){
	if(x == f[x].index)
		return x;
	int father=find(f[x].index,f);
	f[x].index = father;
	f[father].len += f[x].len;
	f[x].len = 0;
	return father;
}

int main(){
	int n,m,p,q,alen;
	cin>>n>>m>>p>>q;
	{people fa[n];
	for(int i=0;i<n;i++){
		fa[i].index = i;
		fa[i].len = 1;
	}
	for(int i=0;i<p;i++){
		int x,y;
		cin>>x>>y;
		x--;
		y--;
		int fx=find(x,fa),fy=find(y,fa);
		fa[fx].index = fa[fy].index;
	}
	for(int i=0;i<n;i++)
		find(i,fa);
	alen = fa[fa[0].index].len;
	}
	
	people fb[m];
	for(int i=0;i<m;i++){
		fb[i].index = i;
		fb[i].len = 1;
	}
	for(int i=0;i<q;i++){
		int x,y;
		cin>>x>>y;
		x = -x;
		y = -y;
		x--;
		y--;
		int fx=find(x,fb),fy=find(y,fb);
		fb[fx].index = fb[fy].index;
	}
	for(int i=0;i<m;i++)
		find(i,fb);
	cout<<min(alen,fb[fb[0].index].len);
	return 0;
}
